#ifndef _MCUDRIVERS_CAN_CAN_H_
#define _MCUDRIVERS_CAN_CAN_H_

#include <xc.h>
#include <stdint.h>
#include <stdbool.h>


/* ECAN message type identifiers */
#define CAN1_MSG_DATA    0x01
#define CAN1_MSG_RTR     0x02
#define CAN1_FRAME_EXT	0x03
#define CAN1_FRAME_STD	0x04
#define CAN1_BUF_FULL	0x05
#define CAN1_BUF_EMPTY	0x06

typedef union {
    struct {
        uint32_t id;
        uint8_t idType;
        uint8_t msgtype;
        uint8_t dlc;
        uint8_t data0;
        uint8_t data1;
        uint8_t data2;
        uint8_t data3;
        uint8_t data4;
        uint8_t data5;
        uint8_t data6;
        uint8_t data7;
    } frame;
    unsigned char array[16];
} uCAN1_MSG;

/* Operation modes */
typedef enum
{
	CAN1_NORMAL_OPERATION_MODE = 0,
	CAN1_DISABLE_MODE = 1,
	CAN1_LOOPBACK_MODE = 2,
	CAN1_LISTEN_ONLY_MODE = 3,
	CAN1_CONFIGURATION_MODE = 4,
	CAN1_LISTEN_ALL_MESSAGES_MODE = 7
}ECAN1_OP_MODES;

typedef enum{
    ECAN1_PRIORITY_HIGH = 0b11,
    ECAN1_PRIORITY_MEDIUM = 0b10,
    ECAN1_PRIORITY_LOW = 0b01,
    ECAN1_PRIORITY_NONE = 0b00
} ECAN1_TX_PRIOIRTY;

#ifdef __cplusplus  // Provide C++ Compatibility

    extern "C" {

#endif

void ECAN1_Initialize_g(void);

bool ECAN1_Transmit_g(ECAN1_TX_PRIOIRTY priority, 
                                    uCAN1_MSG *sendCanMsg);

//在while循环中接收CAN数据
bool ECAN1_ReceiveCanMsg_g(uCAN1_MSG *recMsg);

#endif